<include file="public@header" />
</head>
<style type="text/css">
	#file-wrap{
		height:34px;
		width: 82px;
		position: relative;
		display: inline-block;
		text-align: center;
		line-height: 34px;
		overflow: hidden;
		font-size: 14px;
		cursor: pointer;
		color: #fff;
		vertical-align: middle;
		background-color: #1a242f;
		border-color: #161f29;
	}
	#file-wrap input{
		position: absolute;
		height: 40px;
		z-index: 2;
		right: 0;
		top: 0;
		filter: alpha(opacity=0);
		-moz-opacity: 0;
		opacity: 0;
		cursor: pointer;
		font-size: 16px;
	}
</style>
<body>
<div class="wrap">
	<ul class="nav nav-tabs">
		<li><a href="{:url('advert/index')}">广告列表</a></li>
		<li><a href="{:url('advert/add')}">广告添加</a></li>
		<li class="active"><a>广告修改</a></li>
	</ul>
	<form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('advert/editpost')}">
		<div class="form-group">
			<label class="col-sm-2 control-label"><span class="form-required">*</span>版本号</label>
			<div class="col-md-6 col-sm-10">
                <input type="hidden" name="id" value="{$advertising.id}">
				<input type="text" class="form-control" id="input-a_digital" name="a_digital" maxlength="4" value="{$advertising.a_digital}">
			</div>
		</div>
		<div class="form-group">
			<label for="input-a_title" class="col-sm-2 control-label"><span class="form-required">*</span>广告标题</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" id="input-a_title" name="a_title" maxlength="16" value="{$advertising.a_title}">
			</div>
		</div>
		<div class="form-group">
			<label for="input-a_type" class="col-sm-2 control-label"><span class="form-required">*</span>广告类型</label>
			<div class="col-md-6 col-sm-10" id="input-a_type">
				<select class="form-control" disabled>
					<option value="10" <if condition="$advertising['a_type'] eq 10" >selected </if>>启动页</option>
					<option value="20" <if condition="$advertising['a_type'] eq 20" >selected </if>>直播页</option>
					<option value="30" <if condition="$advertising['a_type'] eq 30" >selected </if>>其他页</option>
				</select>
			</div>
		</div>
		<div class="form-group" <if condition="$advertising['a_type'] neq 20" >style="display: none" </if> >
			<label class="col-sm-2 control-label">明星</label>
			<div class="col-md-6 col-sm-10">
				<input class="form-control" type="text" value="{$star}" disabled/>
			</div>
		</div>
		<div class="form-group">
			<label for="input-a_sort" class="col-sm-2 control-label"><span class="form-required">*</span>排序</label>
			<div class="col-md-6 col-sm-10">
				<input type="number" class="form-control" id="input-a_sort" name="a_sort" min="1" max="100" value="{$advertising.a_sort}">
			</div>
		</div>
        <div class="form-group">
            <label class="col-sm-2 control-label">跳转链接</label>
            <div class="col-md-6 col-sm-10">
                <input type="url" class="form-control" name="a_url" value="{$advertising.a_url}">
            </div>
        </div>
		<div class="form-group">
			<label for="input-s_image" class="col-sm-2 control-label"><span class="form-required">*</span>广告图片</label>
			<div class="col-md-6 col-sm-10">
				<img src="{$advertising.a_image}" id="img" width="128" style="cursor: pointer"/>
				<div id="file-wrap">
					<input type="file" onchange="upload(this)" accept="image/jpg,image/jpeg,image/png" id="input-s_image" name="file" style="display: inline"/>
					选择图片
				</div>
				<input type="button" class="btn btn-default" id="cancel_img" onclick="cancel();" value="取消图片" style="display: none">
				<input type="hidden" name="path" id="path" value="">
				<input type="hidden" name="file" id="file" value="">
				<input type="hidden" name="a_image" value="{$advertising.a_image}">
				<p class="help-block">头像支持jpg,png,jpeg格式,文件大小最大不能超过1M</p>

			</div>
		</div>
		<div class="form-group">
			<label for="input-a_status" class="col-sm-2 control-label"><span class="form-required">*</span>状态</label>
			<div class="col-md-6 col-sm-10" id="input-a_status">
				<select class="form-control" name="a_status">
					<option value="10" <if condition="$advertising['a_status'] eq 10" >selected </if>>启用</option>
					<option value="20" <if condition="$advertising['a_status'] eq 20" >selected </if>>停用</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				<button type="submit" class="btn btn-primary js-ajax-submit">修改</button>
			</div>
		</div>
	</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script type="application/javascript">

    function cancel() {
        $('#file-wrap').show();
        $('#input-s_image').val('').attr('style','display: inline');
        $('#img').attr('src',"{$advertising.a_image}");
        $('#cancel_img').attr('style','display: none');
        $('#path').attr('value','');
        $('#file').attr('value','');

    }

    function upload(obj) {
        var $fileinput = $(obj);
        Wind.css("jcrop");
        Wind.use("ajaxfileupload", "jcrop", "noty", function () {
            $.ajaxFileUpload({
                url: "{:url('advert/uploadImg')}",
                secureuri: false,
                fileElementId: "input-s_image",
                dataType: 'json',
                data: {},
                success: function (data, status) {
                    if (data.code) {
                        $("#file-wrap").hide();
                        $('#cancel_img').show();
                        var src  = '{$simgs}'+ data.data.path + data.data.file;
                        $('#img').attr('src',src);
                        $('#path').attr('value',data.data.path);
                        $('#file').attr('value',data.data.file);
                    } else {
                        noty({
                            text: data.msg,
                            type: 'error',
                            layout: 'center',
                            callback: {
                                afterClose: function () {
                                    reloadPage(window);
                                }
                            }
                        });
                        cancel();
                    }
                },
                error: function (data, status, e) {
                    cancel();
                    alert(e + '\r选择的图片文件错误。请重新选择！');
                }
            });
        });
        return false;
    }
</script>
</body>
</html>